GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 55f45f...84a66e )
by Benjamin
02:43
created

PagerActions.js ➔ ???   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
c 2
b 0
f 0
nc 1
dl 0
loc 5
rs 9.4285
nop 1
1
import {
2
    PAGE_LOCAL,
3
    PAGE_REMOTE,
4
    SET_DATA,
5
    ERROR_OCCURRED
6
} from '../../../constants/ActionTypes';
7
8
import { setLoaderState } from '../../../actions/plugins/loader/LoaderActions';
9
10
import { dismissEditor } from '../../../actions/plugins/editor/EditorActions';
11
12
import Request from '../../../components/plugins/ajax/Request';
13
14
export const setPage = ({ index, type, BUTTON_TYPES }) => {
15
    const pageIndex = type === BUTTON_TYPES.NEXT ? index + 1 : index - 1;
16
17
    return { type: PAGE_LOCAL, pageIndex };
18
};
19
20
export const setPageIndexAsync = ({
21
    pageIndex,
22
    pageSize,
23
    dataSource,
24
    filterFields,
25
    sort,
26
    stateKey,
27
    afterAsyncFunc
28
}) => {
29
30
    if (typeof dataSource === 'function') {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if typeof dataSource === "function" is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
31 View Code Duplication
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
32
        return (dispatch) => {
33
34
            dispatch(dismissEditor({ stateKey }));
35
36
            dispatch(
37
                setLoaderState({ state: true, stateKey })
38
            );
39
40
            dataSource(
41
                {pageIndex, pageSize}, filterFields, sort
42
            ).then((response) => {
43
44
                if (response && response.data) {
45
46
                    dispatch({
47
                        type: SET_DATA,
48
                        data: response.data,
49
                        total: response.total,
50
                        currentRecords: response.items,
51
                        success: true,
52
                        stateKey
53
                    });
54
55
                    if (afterAsyncFunc
56
                        && typeof afterAsyncFunc === 'function') {
57
                        afterAsyncFunc();
58
                    }
59
                }
60
61
                else {
62
63
                    if (response && !response.data) {
64
                        /* eslint-disable no-console */
65
                        console.warn([
66
                            'A response was recieved but',
67
                            'no data entry was found'
68
                        ].join(' '));
69
                        console.warn([
70
                            'Please see',
71
                            'https://github.com/bencripps/react-redux-grid',
72
                            'for documentation'
73
                        ].join(' '));
74
                        /* eslint-enable no-console */
75
                    }
76
77
                    dispatch({
78
                        type: ERROR_OCCURRED,
79
                        error: 'Unable to Retrieve Grid Data',
80
                        errorOccurred: true,
81
                        stateKey
82
                    });
83
                }
84
85
                dispatch(
86
                    setLoaderState({ state: false, stateKey })
87
                );
88
            });
89
        };
90
    }
91
};
92
93
export const setPageAsync = ({
94
    index, pageSize, type, BUTTON_TYPES, dataSource, stateKey
95
}) => {
96
97
    const pageIndex = type === BUTTON_TYPES.NEXT ? index + 1 : index - 1;
98
99
    return (dispatch) => {
100
101
        dispatch(
102
            setLoaderState({ state: true, stateKey })
103
        );
104
105
        return Request.api({
106
            route: dataSource,
107
            method: 'GET',
108
            queryStringParams: {
109
                pageIndex: pageIndex,
110
                pageSize: pageSize
111
            }
112
        }).then((response) => {
113
114
            if (response && response.data) {
115
116
                dispatch({
117
                    type: PAGE_REMOTE,
118
                    pageIndex: pageIndex,
119
                    stateKey
120
                });
121
122
                dispatch({
123
                    type: SET_DATA,
124
                    data: response.data,
125
                    total: response.total,
126
                    currentRecords: response.data,
127
                    success: true,
128
                    stateKey
129
                });
130
131
                dispatch(
132
                    setLoaderState({ state: false, stateKey })
133
                );
134
            }
135
136
            else {
137
                dispatch({
138
                    type: ERROR_OCCURRED,
139
                    error: response,
140
                    errorOccurred: true,
141
                    stateKey
142
                });
143
            }
144
145
        });
146
    };
147
};
148